import { OriginAnalyser, AnalyserOptions } from './OriginAnalyser';

export class AudioAnalyser extends OriginAnalyser {
  audioElement: HTMLAudioElement;
  constructor(audio: HTMLAudioElement | string, options?: AnalyserOptions) {
    super(options);
    this.audioElement = typeof audio === 'string' ? new Audio(audio) : audio;
    this._connectAudioElement();
  }

  private _connectAudioElement() {
    const source = this.audioContext.createMediaElementSource(this.audioElement);
    source.connect(this.audioAnalyser);
  }
}
